/**
 *
 */

var app = getApp()
Page({
	data: {
		root:'',
		siteroot:app.setting.siteroot,
		att_url: app.setting.att_url,
		pagedata:[],
		action: '',
		pagetitle:'直播活动',
		bannerHeight: Math.ceil(290.0 / 750.0 * getApp().screenWidth)
	},
	onReady: function (){
		var the = this
	},
	onLoad: function (opt){
		var the=this;
		wx.setNavigationBarTitle({'title':the.data.pagetitle});
		var route=the.route;
		the.setData({
			route:route,
		});
		if(opt && opt.isgoshare){
				the.setData({
					ShowGoshare:true,
				});
		}
		if(route){
			var path=route.slice(0,-6).split('/');
			app.access.plugin=path.shift();
			app.access.action=path.join('.');
		}
		console.log(opt);
		if(opt){
			app.access.query =app.util.made_query(opt,true);
			app.access.op=opt.op?opt.op:'';
		}
		the.getpagedata();
	},
	getpagedata: function (){
		var the=this;
		app.util.get(app.access,function(pagedata){
			console.log('huodong');console.log(pagedata);
			the.setData({
				pagedata:pagedata,
				pluginnav:app.session.menus,
				action:app.access.plugin+'/'+app.access.action+'/',
			});
			setTimeout(function(){
				the.uplive_status();
			},100);
		});
	},
	uplive_status:function(){
		var the=this;
		var pagedata=the.data.pagedata
		let livePlayer = requirePlugin('live-player-plugin')
		var uproomids=[];
		livePlayer.getLiveStatus({room_id: pagedata.roomid}).then(res => {
			if(pagedata.rooms.live_status!=res.liveStatus){
				pagedata.rooms.live_status= res.liveStatus
				pagedata.rooms.live_statustitle=pagedata.live_status[res.liveStatus];
				uproomids.push({'roomid':pagedata.roomid,'live_status':res.liveStatus})
				app.util.post("jy_weishop/sale.live_index/uproomids/",uproomids, function(res){})
			}
			console.log('get live status');console.log(res);
		})
		.catch(err => {
			console.log('get live status', err)
		})
	},
	getjiang:function(e){
		var the=this;
		var pagedata=the.data.pagedata
		var data=e.currentTarget.dataset;
		app.util.post('jy_weishop/sale.live_huodong/getjiang/id='+data.id+'&roomid='+data.roomid,{});
	},
	gorooms:function(e){
		var data=e.currentTarget.dataset;
		var customParams = encodeURIComponent(JSON.stringify({'path': 'jy_weishop/sale/live_index/index', 'fromroomid': data.roomsid}));
		//url: '/jy_weishop/sale/live_huodong/index?id=11'
		app.util.post("jy_weishop/sale.live_index/uplooktime/id="+data.id, {}, function (res){
			wx.navigateTo({
				url: 'plugin-private://'+app.live_appid+'/pages/live-player-plugin?room_id='+data.roomsid+'&open_share_ticket=1'+'&custom_params='+customParams
			})
		})
	},
	info_login:function(e){
		//根据openid为用户登陆，此处尝试获取用户信息
		var the=this;
		app.util.getUserInfo(e,function(res){
			the.getpagedata();
		});
		the.setData({
			ShowAuthM:false
		})
	},
	mobile_login:function(e){
		var the=this
		var pagedata=the.data.pagedata
		//根据openid为用户登陆，此处尝试获取用户手机号
		app.util.post('core/member.set/setmobile/',e.detail,function(res){
			//console.log(res);
			pagedata.item.mobile=res.mobile
			the.setData({
				'pagedata.item':pagedata.item
			})
		});
	},
	click:function(evt){
		//用户点击事件 data.func 为方法名，data.params 为调用参数！
		var data=evt.currentTarget.dataset;
		//console.log(evt);
		app.util[data.func](data.params);
	},
	onShareAppMessage: function (res) {
		var the = this
		var pagedata = the.data.pagedata
		if (res.from === 'button') {
		}
		var path=the.data.route+'?'+app.access.query;
		if(app.access.op){
			path +='&op='+app.access.op;
		}
		if(pagedata.fromuser){
			path +='&fromuser='+pagedata.fromuser;
		}
		return {
		  title: the.data.pagetitle,
		  path: path,
		  desc: app.setting.sharedesc,
		  success: function(res) {
		  },
		  fail: function(res) {
		  }
		}
	},
})